$(function () {
    var $phone = $("#name");
    var $phe = $("#name_error");
    var $psw = $("#psw");
    var $pse = $("#psw_error");
    var $sub = $("#submit1");
    $sub[0].disabled = true;
    $phone.focus(function () {
        $phe.html("请输入11位手机号作为账户名！");
        $phe.css("color", "rgba(0,200,188,0.8)");
    });
    $phone.blur(function () {
        var phone = $phone.val();
        var reg = /^1[3578][0-9]{9}$/;
        if (phone === '') {
            isError($phe, $sub, "请输入11位手机号作为账户名！");
            return;
        }
        if (reg.test(phone) === false) {
            isError($phe, $sub, "请输入正确的账户名！");
            return;
        }
        $phe.html("检测中...").css("color", "rgba(0,200,188,0.8)");
        $.post("/user/checkPhone.action",
            "phone=" + phone,
            function (data) {
                if (data === 0) {
                    isError($phe, $sub, "该手机号不存在，请重试！");
                    return;
                }
                $phe.html("输入正确！");
                $sub[0].disabled = false;
            });
    });
    $psw.focus(function () {
        $pse.html("请输入密码！");
        $pse.css("color", "rgba(0,200,188,0.8)");
    });
    $psw.blur(function () {
        var psw = $psw.val();
        var reg = /[^0-9A-z_.]/;
        if (psw === '') {
            isError($pse, $sub, "请输入密码！");
            return;
        }
        if (reg.test(psw) === true) {
            isError($pse, $sub, "密码由大小写字母数字下划线点组成！");
            return;
        }
        $pse.html("输入正确！");
        $sub[0].disabled = false;
    })
});

function checkForm() {
    var phone = $("#name").val();
    var psw = $("#psw").val();
    if (phone === ''){
        $("#name_error").html("请输入11位手机号作为账户名！").css("color", "rgba(255,0,0,0.8)");
        return false;
    }
    if (psw === ''){
        $("#psw_error").html("请输入密码！").css("color", "rgba(255,0,0,0.8)");
        return false;
    }
    return true;
}